$(document).ready(function(){
    var DayReportAll = echarts.init(document.getElementById('main'));
    // 指定图表的配置项和数据
    var option = {
        toolbox:{
            'show':true,
            feature:{
                dataZoom:{},
                dataView:{readOnly:false},
                magicType:{type:['line','bar']},
                restore:{},
                saveAsImage:{}
            },
        },
        backgroundColor:"#FFFFFF",
        label:{
                normal:{
                    show:true,
                    position:'top',
                }
            },
            title: {
                text: '',
                subtext:'赢创金融'
            },
            tooltip: {},
            legend: {
                data:['外呼总量','1分钟以上','3分钟以上','约访量','意向客户量']
            },
            xAxis: {
                type:'category',
                data:[],
            },
            calculabe:true,
            yAxis: {
                    type:'value',
                    axisLabel:{formatter:'{value}'}
                },
                series: [{
                    name: '外呼总量',
                    type: 'bar',
                    data: '',
                },
                {
                        name: '1分钟以上',
                        type: 'bar',
                        data: ''
                    },
                {
                        name: '3分钟以上',
                        type: 'bar',
                        data: ''
                    },
                {
                        name: '约访量',
                        type: 'bar',
                        data: ''
                    },
                {
                        name: '意向客户量',
                        type: 'bar',
                        data: ''
                    },

                ],
    };



    // 使用刚指定的配置项和数据显示图表。
    function DayReport(day){

        if(day){
            var url = 'http://192.168.1.106/index.php/home/report/api/order/day/date/'+day;
        }else{
            var url = 'http://192.168.1.106/index.php/home/report/api';
        }
        console.log(url);
        $.getJSON(url,function(result){
            var name = new Array();
            var count = new Array();
            var greater1 = new Array();
            var greater3 = new Array();
            var yuefang = new Array();
            var yixiang = new Array();
            for(var i=0;i<result.data.length;i++){
                name.push(result.data[i].name);
            }
            for(var i=0;i<result.data.length;i++){
                count.push(parseInt(result.data[i].count));
            }
            for(var i=0;i<result.data.length;i++){
                greater1.push(parseInt(result.data[i].greater1));
            }
            for(var i=0;i<result.data.length;i++){
                greater3.push(parseInt(result.data[i].greater3));
            }
            for(var i=0;i<result.data.length;i++){
                yuefang.push(parseInt(result.data[i].yuefang));
            }
            for(var i=0;i<result.data.length;i++){
                yixiang.push(parseInt(result.data[i].yixiang));
            }
            option.title.text = result.title;
            option.xAxis.data = name;
            option.series[0].data = count;
            option.series[1].data = greater1;
            option.series[2].data = greater3;
            option.series[3].data = yuefang;
            option.series[4].data = yixiang;
            DayReportAll.setOption(option);
        });
    }
    DayReport();
    $("#show").click(function(){
        DayReport(day=$("#lastdate").val());
    });
});
